# -*- coding: utf-8 -*-
'''
Created on Nov 24, 2013

@author: LONG HOANG GIANG
'''
from mysql import MySQL
import sys
import logging


logging.basicConfig(level=logging.DEBUG, format='%(levelname)s :: %(asctime)s :: %(message)s', datefmt='%d/%m/%Y %H:%M:%S')

db = MySQL('localhost', 'root', '', 'thuvientruyen')

def createTableStory():
    sql = '''CREATE TABLE story(
                id VARCHAR(50) PRIMARY KEY, 
                name VARCHAR(100) NOT NULL, 
                author VARCHAR(50), 
                url VARCHAR(255), 
                thumbnail VARCHAR(255), 
                description TEXT, 
                numberOfChapter INTEGER DEFAULT 0, 
                isActive TINYINT DEFAULT 1, 
                state VARCHAR(50),
                viewNumber INTEGER DEFAULT 1,
                lastupdate DATETIME,
                timestamp INTEGER,
                tag VARCHAR(200)
            )'''
#     db.execute('DROP TABLE IF EXISTS story')
    db.execute(sql)
    db.execute('''CREATE INDEX name_idx ON story(name)''')
    db.execute('''CREATE INDEX tag_idx ON story(tag)''')
    db.commit()

if __name__ == '__main__':
    
    createTableStory()
    db.close()
    logging.info("finished")
    sys.exit(1)